package com.auoem.radio.ui.other;

import android.os.Bundle;
import android.view.View;

import androidx.annotation.Nullable;

import com.auctus.am.developer.AuHelper;
import com.auctus.am.framework.AmControl;
import com.auctus.am.framework.enums.ApiStatusEnum;
import com.auctus.am.framework.gpio.RootCmdManager;
import com.auctus.am.framework.interfaces.ApiCallback;
import com.auoem.radio.base.BaseActivity;
import com.auoem.radio.common.utils.ToastUtils;
import com.auoem.radio.databinding.ActivityTestCmdBinding;

public class TestCmdActivity extends BaseActivity implements View.OnClickListener {

    ActivityTestCmdBinding mBinding;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mBinding = ActivityTestCmdBinding.inflate(getLayoutInflater());
        setContentView(mBinding.getRoot());
    }

    private void initAm() {
        new Thread(new Runnable() {
            @Override
            public void run() {
//                OemApplication.getApplication().initAmHelper();
            }
        }).start();
    }

    @Override
    public void onClick(View v) {
        if (v == mBinding.btEnablePower) {
//            RootCmdManager.getInstance().enablePower(true);
            RootCmdManager.getInstance().amEnable(true);
        } else if (v == mBinding.btRoot) {
            root();
        } else if (v == mBinding.btCsPower) {
            RootCmdManager.getInstance().csPower(true);
        } else if (v == mBinding.btSetBaudRate) {
            RootCmdManager.getInstance().setBaudRate();
        } else if (v == mBinding.btConnect) {
            RootCmdManager.getInstance().connect(true);
        } else if (v == mBinding.btDisConnect) {
            RootCmdManager.getInstance().connect(false);
        } else if (v == mBinding.btAmCmd) {
            testAmCmd();
        } else if (v == mBinding.btPowerOffCs) {
            RootCmdManager.getInstance().csPower(false);
        } else if (v == mBinding.btPowerOffEn) {
            RootCmdManager.getInstance().enablePower(false);
        } else if (v == mBinding.btGetCsPowerStatus) {
            RootCmdManager.getInstance().getPowerStatus();
        }
    }

    private void testAmCmd() {
       AuHelper.getInstance().getApi().getChipId(new ApiCallback<String>() {
            @Override
            public void onResponse(ApiStatusEnum status, String result, String msg) {
                if (status == ApiStatusEnum.SUCCESS) {
                    ToastUtils.showShortToast(TestCmdActivity.this, "成功： result: " + result);
                } else {
                    ToastUtils.showShortToast(TestCmdActivity.this, "失败: " + msg);
                }
            }
        });
    }

    private void root() {
//        RootCmdManager.getInstance().root();
    }
}
